package edu.bucknell.edash;


import android.widget.ToggleButton;
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;

/**
 * Example activity for starting a separate service that simply blinks the led
 * @author abb011
 *
 */
public class EdashIOIOLooper extends BaseIOIOLooper{
	/** The on-board LED. */
	private DigitalOutput led_;
	private ToggleButton button_;

	EdashIOIOLooper(ToggleButton button){
		System.out.println("In EdashIOIO looper Constructor Button: " + button);
		button_ =button;
	}
	/**
	 * Called every time a connection with IOIO has been established.
	 * Typically used to open pins.
	 * 
	 * @throws ConnectionLostException
	 *             When IOIO connection is lost.
	 * 
	 * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
	 */
	@Override
	protected void setup() throws ConnectionLostException {
		System.out.println("Tried To Setup");
		led_ = ioio_.openDigitalOutput(0, true);
	}

	/**
	 * Called repetitively while the IOIO is connected.
	 * 
	 * @throws ConnectionLostException
	 *             When IOIO connection is lost.
	 * 
	 * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
	 */
	@Override
	public void loop() throws ConnectionLostException {
		led_.write(!button_.isChecked());
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
		}
	}
}


